package com.ruoyi.project.configureSystem.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.configureSystem.domain.CArea;
import com.ruoyi.project.configureSystem.service.ICAreaService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 区域信息Controller
 *
 * @author wangshuo
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/configureSystem/area")
public class CAreaController extends BaseController
{
    @Autowired
    private ICAreaService cAreaService;

    /**
     * 查询区域信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:area:list')")
    @GetMapping("/list")
    public AjaxResult list(CArea cArea)
    {
        List<CArea> list = cAreaService.selectCAreaList(cArea);
        return AjaxResult.success(list);
    }

    /**
     * 导出区域信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:area:export')")
    @Log(title = "区域信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CArea cArea)
    {
        List<CArea> list = cAreaService.selectCAreaList(cArea);
        ExcelUtil<CArea> util = new ExcelUtil<CArea>(CArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取区域信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cAreaService.selectCAreaById(id));
    }

    /**
     * 新增区域信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:area:add')")
    @Log(title = "区域信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CArea cArea)
    {
        return toAjax(cAreaService.insertCArea(cArea));
    }

    /**
     * 修改区域信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:area:edit')")
    @Log(title = "区域信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CArea cArea)
    {
        return toAjax(cAreaService.updateCArea(cArea));
    }

    /**
     * 删除区域信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:area:remove')")
    @Log(title = "区域信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cAreaService.deleteCAreaByIds(ids));
    }
}
